Events of UI Components
This documentation is for an older version of ZK. For the latest one, please click here.
This documentation is for an older version of ZK. For the latest one, please click here.
An event (Event ) is used to notify application what happens. Each type of event is represented by a distinct class. For example, MouseEvent represents a mouse activity, such as clicking.
To respond to an event, an application must register one or more event listeners to it. Here are the ways to register an event listener:
- By specifying the predefined event handler
onXxx
in the markup language. - By calling the
addEventListener
method for the component or the page you want to listen to. - By specifying ZK attributes
forward
,use
,apply
. Please refer to [ZK_ZUML_Reference/The_ZK_User_Interface_Markup_Language/ZK_Attributes/The_forward_Attribute | The forward Attribute] for more information.
In addition to event triggered by user's activity at the browser, an application could fire events by using sendEvent
, postEvent
and echoEvent
methods from the Events class.(Note: These api has to take care about component life cycle, if you use these api outside ZK event handler, please refer to server push.)
How to find out what events a component support
Please look it up at Component Reference. For example, button
supports onClick
, onRightClick
, onDoubleClick
, onFocus
, onBlur
events.
Event Processing is limited to desktop scope
As mentioned above, a desktop is a collection of pages for serving the same URL request. A desktop is also the scope that an event listener could access.
When an event is fired, it is associated with a desktop. ZK separates events by their associated desktops, and pipelines events into separated queues. Therefore, events for the same desktop are processed sequentially. On the other hand, events for different desktops are processed in parallel.
An event listener is allowed to access any component of any page of the associated desktop. It is also allowed to moving components from one page to another as long as they are in the same desktop. On the other hand, it cannot access components belonging to other desktops.